#include "widgets/progressbarwidget.h"
#include "widgets/tomatowidget.h"
#include <QDebug>
#include "services/window/windowservice.h"
using dpfservice::WindowService;

TomatoClockButton::TomatoClockButton(QWidget *parent) : QPushButton(parent), logoLabel(new QLabel(this)), textLabel(new QLabel(this))
{
    initUI();
    connect(this, &QPushButton::clicked, this, &TomatoClockButton::onButtonClicked);
}

// 时间窗UI初始化
void TomatoClockButton::initUI()
{
    layout = new QHBoxLayout(this);
    logoLabel->setAlignment(Qt::AlignLeft | Qt::AlignVCenter);
    textLabel->setAlignment(Qt::AlignRight | Qt::AlignVCenter);
    textLabel->setText("25:00");
    layout->addWidget(logoLabel);
    layout->addWidget(textLabel);
    layout->setContentsMargins(10, 5, 15, 5);
    layout->setSpacing(10);
    setSizePolicy(QSizePolicy::Preferred, QSizePolicy::Preferred);
    adjustSize();
}

// 设置logo
void TomatoClockButton::setLogo(const QPixmap &logo)
{
    // logo缩放
    logoLabel->setPixmap(logo.scaled(20, 20, Qt::KeepAspectRatio, Qt::SmoothTransformation));
    adjustSize();
}

// 设置text
void TomatoClockButton::setText(QString time)
{
    textLabel->setText(time);
    adjustSize();
}


// 窗口自适应
void TomatoClockButton::adjustSize()
{
    QSize size = layout->sizeHint();
    setMinimumSize(size);
    updateGeometry();
}

// 窗口点击事件绑定
void TomatoClockButton::onButtonClicked() {
    emit buttonClicked();
}